package main

import (
	"fmt"
	"sync"
	"time"
)

var syncWait sync.WaitGroup

var mutex sync.RWMutex

func write() {
	mutex.Lock()
	fmt.Println("执行写操作")
	time.Sleep(time.Second * 2)
	mutex.Unlock()
	syncWait.Done()
}

func read() {
	mutex.RLock()
	fmt.Println("----执行读操作")
	time.Sleep(time.Second * 2)
	mutex.RUnlock()
	syncWait.Done()
}

func main() {
	for i := 0; i < 10; i++ {
		syncWait.Add(2)
		go write()
		go read()
	}
	syncWait.Wait()
}
